<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>



<form:form commandName="model" cssClass="validate"
	action="db/entity/save">
	<form:hidden path="id" />
	<table class=" form-table">
		<tbody>
			<tr>
				<td class="td1">实体分类：</td>
				<td class="td2"><form:input path="entityCategory"
						cssClass="required" /></td>
			</tr>
			<tr>
				<td class="td1">名称：</td>
				<td class="td2"><form:input path="name" cssClass="required" />
				</td>
			</tr>
			<tr>
				<td class="td1">表名：</td>
				<td class="td2"><form:input path="tableName" cssClass="hidden" />
					<isperp:listSelector id="tableNameSelector"
						valueControlId="tableName" displayValueCssClass="required"
						url="db/entity/showTables" valueColumn="table_name"
						displayValue="${model.tableName }"
						displayColumn="table_name" showPager="false">
						<isperp:column name="table_name" title="表名称" width="100"></isperp:column>
						<isperp:column name="table_rows" title="总行数" width="30"></isperp:column>
						<isperp:column name="create_time" title="创建时间" width="50"></isperp:column>
					</isperp:listSelector>
				</td>
			</tr>
			<tr>
				<td class="td1">实体类型：</td>
				<td class="td2"　><form:radiobutton path="entityType"
						value="List" />列表 <form:radiobutton path="entityType"
						value="Tree" />树型 <form:radiobutton path="entityType"
						value="Customer" />自定义属性</td>
			</tr>
			<tr>
				<td class="td1">特性：</td>
				<td class="td2"　><form:checkbox path="useForImport"
						label="用于导入" value="1" />
					<div style="padding-top:5px;">


						<label>用于slm计算：${slmDesc }；</label><a class="nui-txt-link"
							href="javascript:isperp.openDialog({windowSize:'normal',contentUrl:'db/entity/monitorMapEdit?tableName=${model.tableName }'})">[修改]</a>
					</div></td>
			</tr>
			<tr>
				<td class="td1">sql定义：</td>
				<td class="td2"　><form:input path="sqlStr" cssStyle="width:80%" />
				</td>
			</tr>

			<tr>
				<td class="td1">描述：</td>
				<td class="td2"><form:textarea path="description"></form:textarea>
				</td>
			</tr>
			<tr>
				<td class="td1">排序：</td>
				<td class="td2"　><form:input path="orderNum" cssClass="number" />

				</td>
			</tr>
		</tbody>
	</table>

	<div class="box no-border">
		<div class="header">
			<h2>实体字段</h2>
		</div>
		<isperp:grid url="db/entityField/list?entityId="
			urlExtScript="function(){return $('#id').val();}"
			gridId="entityFieldGrid" gridTitle="实体字段" cusFormatterActions="true"
			showSearchbar="false" showPager="false"
			beforeCreateAction="'entityId='+$('#id').val()"
			cusEditUrl="db/entityField/edit" cusDeleteUrl="db/entityField/delete"
			ondbClickRowEvent="entityFieldGrid.edit(rowid);">
			<jsp:attribute name="toolbar">
				<isperp:toolbar id="entityFieldToolbar">
					<isperp:button id="entityFieldCreate" text="新增" icon="icon-plus"
						onclick="entityFieldGrid.create();"></isperp:button>	
					<isperp:button id="entityFieldGenerate" text="生成实体列"
						icon="icon-plus" onclick="entityFieldGenerate_Onclick();"></isperp:button>
				</isperp:toolbar>
			</jsp:attribute>
			<jsp:body>
				<isperp:column name="id" title="id" hidden="true"></isperp:column>
				<isperp:column name="name" title="名称" width="100">
				</isperp:column>
				<isperp:column name="fieldType" title="字段类型" width="100">
				</isperp:column>
				<isperp:column name="columnName" title="数据库列名" width="120">
				</isperp:column>
				<isperp:column name="useForImport" title="用于导入" width="70"
					formatter="checkbox"> 
				</isperp:column>
				<isperp:column name="useForChange" title="用于变更" width="70"
					formatter="checkbox">
				</isperp:column>
				<isperp:column name="notnull" title="非空" width="70"
					formatter="checkbox">
				</isperp:column>
				<isperp:column name="uniqueKey" title="唯一键" width="70"
					formatter="checkbox">
				</isperp:column>
				<isperp:column name="dataChangeLog" title="数据日志" width="70"
					formatter="checkbox">
				</isperp:column>
				<isperp:column name="domainField" title="项目域标识" width="60"
					align="center" formatter="checkbox">
					</isperp:column>
			</jsp:body>
		</isperp:grid>
	</div>


</form:form>
<script type="text/javascript">
	function entityFieldGenerate_Onclick() {
		//先提交表单
		isperp.submitForm({
			success : function() {

				isperp.confirmAlert("您确定要重新构造实体的数据列吗？", {
					yes : function() {
						$.post("db/entity/generateDbEntityField", {
							id : $("#id").val()
						}, function(data) {
							entityFieldGrid.reload();
						});
					}
				});
			}
		});
	}

	function useForSlmOnclick(obj) {
		if (obj.checked) {
			$("#divUseForSlm").show();
		} else {
			$("#divUseForSlm").hide();
		}
	}

	var useForSlmValue = "${model.useForSlm}";

	if (useForSlmValue == "true") {
		$("#divUseForSlm").show();
	}
</script>

<isperp:buttonList>
	<button class="submit" onclick="isperp.submitForm();return false;">
		<span class="icon icon-save"></span>提交
	</button>
</isperp:buttonList>
